package com.btex.app.net;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest;

/**
 * Created by wcx on 16/3/16.
 */
public class NetConnection {
    private String url;
    public NetConnection(String url) {
        this.url = url;
    }

    /**
     * get请求 不带参数
     */
    public void get(){
        new HttpUtils().send(HttpRequest.HttpMethod.POST, url, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {

            }

            @Override
            public void onFailure(HttpException error, String msg) {

            }
        });
    }

    /**
     * post 请求
     * @param kvs 参数
     */
    public void post(final String ... kvs){
        RequestParams params = new RequestParams();
        for (int i = 0; i < kvs.length; i+=2) {
            params.addQueryStringParameter(kvs[i], kvs[i + 1]);
        }
//        params.addHeader();
//        params.setHeader();


        new HttpUtils().send(HttpRequest.HttpMethod.POST, url,params, new RequestCallBack<String>() {
            @Override
            public void onSuccess(ResponseInfo<String> responseInfo) {

            }

            @Override
            public void onFailure(HttpException error, String msg) {

            }
        });
    }

}
